<template>
  <div class="_wz_cent_main _wz_accredit">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form :model="formDataSearch" label-position="right" :label-width="100" inline>
        <FormItem label="从业人员">
          <i-input v-model="formDataSearch.driverName" placeholder="从业人员" clearable />
        </FormItem>
        <FormItem label="从业类型">
          <i-select v-model="formDataSearch.driverType" filterable placeholder="从业类型" clearable>
            <Option v-for="item in personType" :value="item.code" :key="item.code">{{item.value}}</Option>
          </i-select>
        </FormItem>
        <FormItem label="使用类型" v-if="searchType">
          <i-select v-model="formDataSearch.authType" filterable placeholder="使用类型" clearable>
            <Option v-for="item in authType" :value="item.type" :key="item.type">{{item.value}}</Option>
          </i-select>
        </FormItem>
        <FormItem label="身份证号" v-if="searchType">
          <i-input v-model="formDataSearch.driverIdentifyNum" placeholder="身份证号" clearable />
        </FormItem>
        <FormItem label="运输企业" v-if="searchType">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="请选择运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true">
      <p slot="title">列表</p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>

  </div>
</template>
<script>
  import wzTbale from "../../../components/table/table";

  export default {
    components: {
      wzTbale,//列表
    },
    data() {
      return {
        searchType:false,//搜索条件
        subDeptList: [],//运输企业
        deptTypeList: [],//企业类型字典
        personType: [],//从业类型
        formDataSearch: {},//搜索表单数据
        authType:[
          {type: 1, value: '消费', color: 'primary'},
          {type: 2, value: '充值', color: 'success'},
          {type: 3, value: '重置', color: 'warning'},
        ],
        tableData: {
          url: this.apiUrl.coreDriverCoreAuthRecordPageList,//请求地址
          method: 'post',//请求方式
          where: {},//搜索条件
          height: 'auto',//表格高度 auto
          page: true,//分页是否使用
          columns: [//表头数据
            {type: 'index', width: 70, align: 'center', title: '序号'},
            {
              title: '使用类型', minWidth: 120, key: 'authType', render: (h, params) => {
                let data = this.authType.filter(item => params.row.authType == item.type)[0];
                return h('Tag', {props: {type: 'dot', color: data.color}}, data.value);
              }
            },
            {
              title: '从业人员', key: 'driverName', minWidth: 100,
              render: (h, params) => {
                return h('span', !!params.row.driverName ? params.row.driverName : '--');
              }
            },
            {
              title: '从业类型', key: 'driverTypeName', minWidth: 120,
              render: (h, params) => {
                return h('span', !!params.row.driverTypeName ? params.row.driverTypeName : '--');
              }
            },
            {
              title: '使用授权次数企业', key: 'deptName', minWidth: 260,
              render: (h, params) => {
                return h('span', !!params.row.deptName ? params.row.deptName : '--');
              }
            },
            // {
            //   title: '消耗授权次数企业', key: 'actualDeptName', minWidth: 260,
            //   render: (h, params) => {
            //     return h('span', !!params.row.actualDeptName ? params.row.actualDeptName : '--');
            //   }
            // },
            {title: '变化数量', minWidth: 120, key: 'authUseCount'},
            {
              title: '当前剩余', minWidth: 120, key: 'authAllCount',
              render: (h, params) => {
                return h('span', !!params.row.authAllCount ? params.row.authAllCount : 0);
              }
            },

            {
              title: '身份证号', key: 'driverIdentifyNum', minWidth: 180,
              render: (h, params) => {
                return h('span', !!params.row.driverIdentifyNum ? params.row.driverIdentifyNum : '--');
              }
            },
            {
              title: '操作时间', key: 'createTime', minWidth: 180, render: (h, params) => {
                return h('span', !!params.row.createTime ? params.row.createTime : '--');
              }
            },
          ],
          format: {//返回数据格式
            list: ['data'],//数据list
            count: ['count'],//数据总量
          },
        },
      }
    },
    beforeCreate() {//beforeCreate创建前状态

    },
    created() {//created创建完毕状态
    },
    beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

    },
    mounted() {//mounted 挂载结束状态
      let that = this;
      //运输企业
      that.axios.post(that.apiUrl.coreDeptCoreDeptList,{}).then(res => {
        if (!!res) {
          that.subDeptList = res.data.data;
        }
      }).catch(err => {
        console.log("失败", err)
      })


      //从业类型
      that.axios.post(that.apiUrl.systemDictSystemDictList, {type: 'person_type'}).then(res => {
        if (!!res) {
          that.personType = res.data.data;
        }
      }).catch(err => {
        console.log('失败', err);
      })

      //企业类型
      that.axios.post(that.apiUrl.systemDictSystemDictList, {type: 'transport_type'}).then(res => {
        if (!!res) {
          that.deptTypeList = res.data.data;
        }
      }).catch(err => {
        console.log('失败', err);
      })
    },
    methods: {//执行的方法
      searchSubmit() {//搜索
        this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
        this.$refs.wzTbale.tableLoadData(true);

      }
    },
    watch: {//监听

    },
    props: {//接收来自父组件的数据

    },
    beforeUpdate() {//beforeUpdate 更新前状态

    },
    updated() {//updated 更新完成状态

    },
    beforeDestroy() {//beforeDestroy 销毁前状态

    },
    destroyed() {//destroyed 销毁完成状态

    }
  }
</script>
<style lang="less">
  ._wz_accredit {
    height: 100%;
    display: flex;
    flex-direction: column;


  }
</style>
